<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!--********************************************************************
* 该示例需要引入 
* G6 (https://github.com/antvis/G6)
*********************************************************************-->
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
    <title data-i18n="resources.title_l7_monsoon_distribution"></title>
    <script type="text/javascript" include="jquery" src="../js/include-web.js"></script>
    <style>
      body {
        margin: 0;
        padding: 0;
        width: 100%;
        height: 100vh;
        overflow: hidden;
      }
      #map {
        width: 100%;
        height: 100%;
      }
    </style>
  </head>

  <body>
    <div id="map"></div>
    <script type="text/javascript" include="L7,maplibre-gl-enhance" src="../../dist/maplibregl/include-maplibregl.js"></script>
    <script type="text/javascript">
      var host = window.isLocal ? window.server : 'https://iserver.supermap.io';
      var attribution =
        "<a href='https://maplibre.org/' target='_blank'>© MapLibre </a>" +
        " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
        " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ";

      var tileURL = host + '/iserver/services/map-china/rest/maps/ChinaDark/zxyTileImage.png?z={z}&x={x}&y={y}';
      var map = new maplibregl.Map({
        container: 'map',
        style: {
          version: 8,
          sources: {
            'raster-tiles': {
              attribution: attribution,
              type: 'raster',
              tiles: [tileURL],
              tileSize: 256
            }
          },
          layers: [
            {
              id: 'simple-tiles',
              type: 'raster',
              source: 'raster-tiles',
              minzoom: 0,
              maxzoom: 22
            }
          ]
        },
        center: [105, 35],
        zoom: 4
      });

      map.on('load', function () {
        map.getL7Scene().then((scene) => {
          scene.addImage('arrRed', '../img/A_KWGqT6Oz50EAAAAAAAAAAAAAARQnAQ.png');
          scene.addImage('arrBlue', '../img/A_ZKhURq53OgIAAAAAAAAAAAAAARQnAQ.png');
          fetch('https://iclient.supermap.io/web/data/L7/4c02515b-cb7a-47be-93cf-5596731ef982.json')
            .then((res) => res.json())
            .then((monsoon) => {
              const { data, borderData } = monsoon;

              var imageLayer = new maplibregl.supermap.L7Layer({ type: 'PointLayer' });
              var l7Layer = imageLayer.getL7Layer();
              l7Layer
                .source(data)
                .shape('wind', (wind) => {
                  if (wind === 'up') {
                    return 'arrBlue';
                  }
                  return 'arrRed';
                })
                .rotate('r', (r) => Math.PI * r)
                .size(15)
                .style({
                  rotation: 0,
                  layerType: 'fillImage'
                });
              map.addLayer(imageLayer);

              var border = new maplibregl.supermap.L7Layer({ type: 'LineLayer' });
              border
                .getL7Layer()
                .source(borderData)
                .size(1.5)
                .color('#575757')
                .style({
                  lineType: 'dash',
                  dashArray: [5, 5]
                });
              map.addLayer(border);

              var text = new maplibregl.supermap.L7Layer({ type: 'PointLayer' });
              text
                .getL7Layer()
                .source(
                  [
                    { lng: 90, lat: 35, n: '非季风区' },
                    { lng: 125, lat: 30, n: '季风区' }
                  ],
                  {
                    parser: {
                      type: 'json',
                      x: 'lng',
                      y: 'lat'
                    }
                  }
                )
                .shape('n', 'text')
                .size(25)
                .color('#575757')
                .style({
                  spacing: 20
                });
              map.addLayer(text);
            });
        });
      });
    </script>
  </body>
</html>
